package com.xjy.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.utils.PageUtils;
import com.xjy.system.domain.ReportExpendBudgetDetail;
import com.xjy.system.domain.bo.ReportExpendBudgetDetailQueryBo;
import com.xjy.system.domain.vo.ReportExpendBudgetDetailVo;
import com.xjy.system.mapper.ReportExpendBudgetDetailMapper;
import com.xjy.system.service.IReportExpendBudgetDetailService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 报销科目明细Service业务层处理
 *
 * @author mlb
 * @date 2022-03-22
 */
@Service
public class ReportExpendBudgetDetailServiceImpl extends ServicePlusImpl<ReportExpendBudgetDetailMapper, ReportExpendBudgetDetail> implements IReportExpendBudgetDetailService {

    @Override
    public ReportExpendBudgetDetailVo queryById(Long projId){
        return getVoById(projId, ReportExpendBudgetDetailVo.class);
    }

    @Override
    public TableDataInfo<ReportExpendBudgetDetailVo> queryPageList(ReportExpendBudgetDetailQueryBo bo) {
        PagePlus<ReportExpendBudgetDetail, ReportExpendBudgetDetailVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), ReportExpendBudgetDetailVo.class);
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<ReportExpendBudgetDetailVo> queryList(ReportExpendBudgetDetailQueryBo bo) {
        return listVo(buildQueryWrapper(bo), ReportExpendBudgetDetailVo.class);
    }

    private LambdaQueryWrapper<ReportExpendBudgetDetail> buildQueryWrapper(ReportExpendBudgetDetailQueryBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportExpendBudgetDetail> lqw = Wrappers.lambdaQuery();
        lqw.like(StrUtil.isNotBlank(bo.getProjName()), ReportExpendBudgetDetail::getProjName, bo.getProjName());
        lqw.like(StrUtil.isNotBlank(bo.getSubjectName()), ReportExpendBudgetDetail::getSubjectName, bo.getSubjectName());
		lqw.eq(null != bo.getProjId(),ReportExpendBudgetDetail::getProjId,bo.getProjId());
		lqw.eq(null != bo.getBudgetId(),ReportExpendBudgetDetail::getBudgetId,bo.getBudgetId());

		lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
            ReportExpendBudgetDetail::getCreateTime ,params.get("beginCreateTime"), params.get("endCreateTime"));
        return lqw;
    }

}
